package com.bw.controller;

import com.bw.entity.User;
import com.bw.mapper.UserMapper;
import org.spring.kun.common.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ListController {

    /**
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/list.do")
    public String list(Model model, HttpServletRequest request){
      // 如何获取当前登录用户  从request里获取cookie ，从cookie里获取token， 解析token（解密）为用户
        User userFromRequest = TokenUtils.getLoginUserFromRequest(request, User.class);

        model.addAttribute("name",userFromRequest.getName());
        model.addAttribute("nickName",userFromRequest.getNickName()); // 给页面传值
        model.addAttribute("avatarUrl",userFromRequest.getAvatarUrl());

        return "list";
    }
}
